home *** CD-ROM | disk | FTP | other *** search
- #include <exec/execbase.h>
- #include <dos/dos.h>
- #include <proto/exec.h>
- #include <proto/dos.h>
-
- #include <string.h>
- struct ExecBase *SysBase;
- struct DosLibrary *DOSBase;
-
- struct RDArgs *RDArgs;
-
- struct {
- BYTE *Device;
- LONG *Unit;
- } Args;
-
- struct IOStdReq *IOReq;
- struct MsgPort *ReplyPort;
- LONG Unit;
- LONG Warn=20;
-
- VOID cleanup(BYTE str[]);
-
- LONG __saveds main(VOID)
- {
- SysBase=*(struct ExecBase **)4;
-
- if ((DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",0))==NULL)
- return 100;
-
- if (DOSBase->dl_lib.lib_Version<36)
- {
- cleanup("You need Kickstart 2.0 or better.\n");
- return 20;
- }
-
- if ((RDArgs=ReadArgs("DEVICE/A,UNIT/N/O",(LONG *)&Args,NULL))==NULL)
- {
- cleanup("Invalid arguments.\n");
- return 20;
- }
-
- if (Args.Unit==NULL)
- Args.Unit=&Unit;
-
- if ((ReplyPort=(struct MsgPort *)CreateMsgPort())==NULL)
- {
- cleanup("Cannot create port.\n");
- return 20;
- }
-
- if ((IOReq=(struct IOStdReq *)
- CreateIORequest(ReplyPort,sizeof(struct IOStdReq)))==NULL)
- {
- cleanup("Cannot create IO request.\n");
- return 20;
- }
-
- Warn=(OpenDevice(Args.Device,*Args.Unit,(struct IORequest *)IOReq,0) ? 5:0);
-
- Printf("%s, unit %ld %s.\n",Args.Device,*Args.Unit,
- Warn ? "doesn't exist":"exists");
-
- cleanup(NULL);
- return Warn;
- }
-
-
- VOID cleanup(BYTE str[])
- {
- if (str!=NULL)
- Write(Output(),str,strlen(str));
- if (ReplyPort!=NULL)
- DeleteMsgPort(ReplyPort);
- if (!Warn)
- CloseDevice((struct IORequest *)IOReq);
- if (IOReq!=NULL)
- DeleteIORequest((struct IORequest *)IOReq);
- if (RDArgs!=NULL)
- FreeArgs(RDArgs);
- if (DOSBase!=NULL)
- CloseLibrary((struct Library *)DOSBase);
- }
-